package wangjg.xuexiban.activity.card;

import java.util.List;

import wangjg.xuexiban.R;
import wangjg.xuexiban.widget.MyViewPager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class CardPagerActivity extends BasicCardActivity implements OnPageChangeListener {
    
	protected MyViewPager myPager;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.card_list2);
		this.loadDataList();
	}
    
	//初始化ViewPager
	protected void initContentView(){
		if(myPager==null){
	        myPager = (MyViewPager) findViewById(R.id.vPager);
	        MyPagerAdapter pagerAdapter = new MyPagerAdapter(this.getCardList());
	        myPager.setAdapter(pagerAdapter);
			myPager.setOnPageChangeListener(this);
		}
	}
	
    public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(0, 1, 1, "测试一下");
		return super.onCreateOptionsMenu(menu);
	}
    
	public boolean onOptionsItemSelected(MenuItem item) {
		if(item.getItemId()==1){
			String categoryId = getIntent().getStringExtra("category_path");
			Intent intent = new Intent(this, ExamActivity2.class);
			intent.putExtra("category_path", categoryId);
			startActivity(intent);
		}
		
		Log.d("zzz", "list:"+getCardList());
		return super.onOptionsItemSelected(item);
	}

	/**
	 * ViewPager适配器
	 */
	private class MyPagerAdapter extends ListPagerAdapter {

		public MyPagerAdapter(List list){
			super(list);
		}
		
		protected View getItemView(int position) {
			return createPageView(position);
		}
		
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {
		Log.d(this.getClass().getSimpleName(), "onPageScrollStateChanged, arg0="+arg0);
	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
		Log.d(this.getClass().getSimpleName(), "onPageScrolled, arg0="+arg0);
	}

	@Override
	public void onPageSelected(int arg0) {
		Log.d(this.getClass().getSimpleName(), "onPageSelected, arg0="+arg0);
	}

}

